<?php

namespace App\Providers;

use App\Models\SchoolUser;
use App\Models\User;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Models\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        // 检查是否是学校管理员
        Gate::define("checkSchoolAdmin", function ($user, $schoolId) {
             return SchoolUser::where(
                [
                    "school_id"=>$schoolId,
                    "user_id"=>$user->id,
                    "identity"=> "school"
                ]
             )->exists();
        });
    }
}
